package com.zone.trigger.http;

import com.zone.domain.credit.model.entity.UserCreditAccountEntity;
import com.zone.domain.credit.service.IUserCreditAccountQuoteService;
import com.zone.trigger.api.IUserCreditService;
import com.zone.types.model.Response;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.Objects;

/**
 * @author: zongzi
 * @description: 用户积分相关接口
 * @date: 2025/3/15
 */
@CrossOrigin("${app.config.cross-origin}")
@RestController
@RequestMapping("/api/${app.config.api-version}/user/credit")
@DubboService(version = "1.0")
public class UserCreditController implements IUserCreditService {

    @Autowired
    private IUserCreditAccountQuoteService userCreditAccountQuoteService;

    /**
     * 查询用户积分账户剩余积分
     *
     * @param userId 用户id
     * @return 用户剩余积分
     */
    @GetMapping("/query_user_credit_account")
    @Override
    public Response<BigDecimal> queryUserCreditAccount(@RequestParam String userId) {
        UserCreditAccountEntity userCreditAccount = userCreditAccountQuoteService.queryCreditAccount(userId);
        if (Objects.isNull(userCreditAccount)) {
            return Response.success(BigDecimal.ZERO);
        }
        return Response.success(userCreditAccount.getAvailableAmount());
    }
}
